package demo4;
abstract class Animal {
    public String name;

    public Animal(String name) {
        this.name = name;
    }
}
interface IRunning {
    public void run();
}
interface ISwimming {
    void swim();
}
interface IFly {
    void fly();
}

class Dog extends Animal implements IRunning {//不能进行多继承，不支持
          //先继承在实现
    public Dog(String name) {//帮助父类构造
        super(name);
    }

    @Override
    public void run() {
        System.out.println(name + "正在用四条狗腿跑");
    }
}
class Fish extends Animal implements ISwimming {

    public Fish(String name) {
        super(name);
    }

    @Override
    public void swim() {
        System.out.println(name + "正在游泳");
    }
}

class Bird extends Animal implements IFly {

    public Bird(String name) {
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(name+"正在飞");
    }
}
class Duck extends Animal implements IRunning,IFly,ISwimming {

    public Duck(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(name + "正在用两条腿跑");
    }

    @Override
    public void swim() {
        System.out.println(name + "正在用两条腿在游泳");
    }

    @Override
    public void fly() {
        System.out.println(name + "正在用翅膀飞");
    }
}

class Robot implements IRunning {

    @Override
    public void run() {
        System.out.println("机器人在用机器腿跑步");
    }
}

public class Test {//一个类可以实现多个接口
    //只要实现了IRunning接口的 都可以接受
    public static void walk(IRunning iRunning) {
        iRunning.run();
    }
    public static void swim(ISwimming iSwimming) {
        iSwimming.swim();
    }

    /*//一定是一个动物
    public static void func(Animal animal) {

    }*/

    public static void main(String[] args) {
        walk(new Dog("旺财"));
        walk(new Duck("唐老鸭"));
        walk(new Robot());
        System.out.println("===========");
        swim(new Fish("鲤鱼"));
        swim(new Duck("唐老鸭"));
    }
}
